package com.pingan.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;

public class GetMCCode extends UDF {

	public String evaluate(String queryStr) throws Exception {
		return getMCCode(queryStr);
	}

	public String getMCCode(String queryStr) throws Exception {
		String code = null;
		if (queryStr == null || "".equals(queryStr)) {
			return code;
		} else {
			String[] array = queryStr.split("&");

			if (array.length > 0) {
				for (String s : array) {
					if (s.startsWith("WT.mc_id=")) {
						code = s.split("=")[1];
					}
				}
			}
			return code;
		}
	}

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		GetMCCode g = new GetMCCode();
		System.out
				.println(g
						.evaluate("WT.mc_id=wap-CXX-BDZH-07-018-85438400c42c20b3ijjjjjjjjjjjjjjjjjjjjk"));
	}

}
